module.exports = app => {
  const DataTypes = app.Sequelize
  const sequelize = app.model
  const attributes = {
    id: {
      type: DataTypes.UUID,
      allowNull: false,
      primaryKey: true,
      defaultValue: DataTypes.UUIDV1,
      comment: '主键 唯一标识'
    },
    categoryId: {
      type: DataTypes.STRING(32),
      comment: '课程类别id',
      field: 'category_id'
    },
    courseId: {
      type: DataTypes.STRING(32),
      comment: '课程id',
      field: 'course_id'
    },
    termId: {
      type: DataTypes.STRING(32),
      comment: '课程期数id',
      field: 'term_id'
    },
    enrollCount: {
      type: DataTypes.INTEGER,
      comment: '选课数量',
      field: 'enroll_count'
    },
    outLine: {
      type: DataTypes.TEXT,
      comment: '内容大纲',
      field: 'out_line'
    },
    startTime: {
      type: DataTypes.DATE,
      comment: '开课时间',
      field: 'start_time'
    },
    endTime: {
      type: DataTypes.DATE,
      comment: '结课时间',
      field: 'end_time'
    },
    createTime: {
      type: DataTypes.DATE,
      comment: '创建日期',
      field: 'create_time'
    },
    createUser: {
      type: DataTypes.UUID,
      comment: '创建用户',
      field: 'create_user'
    },
    lastTime: {
      type: DataTypes.DATE,
      comment: '修改日期',
      field: 'last_time'
    },
    lastUser: {
      type: DataTypes.UUID,
      comment: '修改用户',
      field: 'last_user'
    },
    deleteFlag: {
      type: DataTypes.BOOLEAN,
      comment: '是否删除（1是，0否）',
      field: 'delete_flag',
      allowNull: false,
      defaultValue: false
    }
  }
  const options = {
    tableName: 'mooc_course_terminfo'
  }
  const CourseTerminfo = sequelize.define('terminfo', attributes, options)
  CourseTerminfo.associate = function() {
    app.model.CourseTerminfo.belongsTo(app.model.Course, { foreignKey: 'courseId' })
  } // 一个期数属于一门课程
  return CourseTerminfo
}
